home *** CD-ROM | disk | FTP | other *** search
- // Get user input in graphics mode per keystroke
- // Michael J. Campbell, 1994
-
- #include <graphics.h>
- #include <string.h>
- #include <ctype.h>
- #include <conio.h>
- #include <stdio.h>
- #include "keycodes.h"
-
- extern char text[30];
- int ESC_pressed = 0;
-
- void write_text(int x, int y, int tcolor, int tshadow, int blankcolor, int length, int SHADOW)
- /*
- Writes text to the screen as it is typed in the graphics mode in the default
- font of size 0.
- Call write_text(A,B,C,D,E,F,G) where:
- A = starting x coordinate of the text
- B = starting y coordinate of the text
- C = text color
- D = text shadow
- E = color of surrounding that text is in, use for erasing while back
- spacing
- F = maximum length of the text string
- G = set to 1 if you want a "stamped" look to your text
- */
- {
-
- int alpha=0, beta=0, xx=0, offset;
- char buffer[1];
- char character[60];
-
-
- if(SHADOW) offset = 0; //If user doesn't choose a shadowed text
- else offset = 1; //If user chooses a shadowed text
-
- strcpy(buffer,"");
-
- settextstyle(SMALL_FONT,HORIZ_DIR,4);
- settextjustify(LEFT_TEXT,CENTER_TEXT);
-
- for(;;) //Loop until carriage return encountered
- {
- //Draw the cursor
- setcolor(tshadow);
- outtextxy(x+beta,y,"█");
-
- //Get a keystroke from the user
- character[alpha] = getch();
-
- //Clear old cursor position
- setcolor(blankcolor);
- outtextxy(x+beta,y,"█");
-
- //Check for the end of the text string entered
- if(character[alpha] == ENTER)
- {
- character[alpha] = '\0';
- if(character[alpha-1] == '\\') character[alpha-1] = '\0';
- break;
- }
- if(character[alpha] == ESC)
- {
- ESC_pressed = 1;
- break;
- }
- //Check for a backspace to erase mistyped keys
- if(character[alpha] == BACK_SPACE || alpha >= length)
- {
- //The next lines erase the old characters on the screen
- //and clear the characters in the string
- beta-=7;
- if(beta <= 0) beta = 0;
- sprintf(buffer,"%c",character[alpha-1]);
- setcolor(blankcolor);
- outtextxy(x+beta,y,"█");
- outtextxy(x+beta+1,y+1,"█");
-
-
-
- alpha=alpha-1;
-
- //Don't backspace pass beginning
- if(alpha < 0) alpha = 0;
-
- //Goto beginning of loop
- continue;
- }
- else
- {
- //Put typed character into the buffer
- sprintf(buffer,"%c",toupper(character[alpha]));
-
- if(SHADOW)
- {
- setcolor(tshadow);
- outtextxy(x+beta,y,"*");
- }
-
- setcolor(tcolor);
- outtextxy(x+1+beta-offset,y+1-offset,"*");
-
- //Increment the character count and move to the next letter position
- alpha++;
- beta+=7;
- }
-
- } //End of infinite for loop
- if(character[alpha] == ESC)
- {
- ESC_pressed = 1;
- }
- else
- {
- //Clear any old values left in the text string
- strcpy(text,"");
-
- //Write the characters into the text string
- for(xx=0;xx<alpha;xx++)
- {
- sprintf(buffer,"%c",character[xx]);
- strcat(text,buffer);
-
- //When end of string is encountered, return to calling program
- if(character[xx] == '\0') break;
- }
- }
- }
-